package net.xumf.support.utils;

import java.util.concurrent.ConcurrentHashMap;

public class FrequencyUtil {

    private static final ConcurrentHashMap<String, Long> timeCache = new ConcurrentHashMap<>();
    private static final ConcurrentHashMap<String, Integer> countCache = new ConcurrentHashMap<>();

    public static void setCount(String key, int count) {
        countCache.put(key, count);
    }

    public static long increment(String key, int number) {
        return countCache.merge(key, number, (a, b) -> a + b);
    }

    public static Long getTimeOut(String key) {
        return timeCache.get(key);
    }

    public static void setTimeOut(String key, long time) {
        long currentTime = System.currentTimeMillis();
        long timeout = currentTime + time;
        timeCache.put(key, timeout);
    }
}
